home *** CD-ROM | disk | FTP | other *** search
- head 1.3;
- branch ;
- access ;
- symbols sprited:1.3.1;
- locks ; strict;
- comment @ * @;
-
-
- 1.3
- date 89.06.19.14.15.25; author jhh; state Exp;
- branches 1.3.1.1;
- next 1.2;
-
- 1.2
- date 88.07.19.13.26.51; author mendel; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 88.04.25.21.39.16; author ouster; state Exp;
- branches ;
- next ;
-
- 1.3.1.1
- date 91.12.02.21.28.39; author kupfer; state Exp;
- branches ;
- next ;
-
-
- desc
- @@
-
-
- 1.3
- log
- @now returns 0 if argument is 0 (unix compatible)
- @
- text
- @/*
- * ffs.c --
- *
- * Source code for the "ffs" library routine.
- *
- * Copyright 1988 Regents of the University of California
- * Permission to use, copy, modify, and distribute this
- * software and its documentation for any purpose and without
- * fee is hereby granted, provided that the above copyright
- * notice appear in all copies. The University of California
- * makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without
- * express or implied warranty.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: /sprite/src/lib/c/bstring/RCS/ffs.c,v 1.2 88/07/19 13:26:51 mendel Exp Locker: jhh $ SPRITE (Berkeley)";
- #endif not lint
-
- /*
- * The following mask is used to detect proper alignment of addresses
- * for doing word operations instead of byte operations. It is
- * machine-dependent. If none of the following bits are set in an
- * address, then word-based operations may be used. This value is imported
- * from machparam.h
- */
-
- #include "machparam.h"
-
- #define WORDMASK WORD_ALIGN_MASK
-
- /*
- * Used to find the first set bit. Value of the array is the index of the
- * first set bit in the array index.
- */
- static int lookup[16] = {
- 0, /* 0x0 */
- 1, /* 0x01 */
- 2, /* 0x10 */
- 1, /* 0x11 */
- 3, /* 0x100 */
- 1, /* 0x101 */
- 2, /* 0x110 */
- 1, /* 0x111 */
- 4, /* 0x1000 */
- 1, /* 0x1001 */
- 2, /* 0x1010 */
- 1, /* 0x1011 */
- 3, /* 0x1100 */
- 1, /* 0x1101 */
- 2, /* 0x1110 */
- 1 /* 0x1111 */
- };
-
- /*
- *----------------------------------------------------------------------
- *
- * ffs --
- *
- * Find the least-significant 1-bit in the argument.
- *
- * Results:
- * If there are no one-bits in the argument, then 0 is returned.
- * Otherwise the return value is the index of the least-significant
- * 1 bit, where "1" corresponds to the low-order bit.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
- int
- ffs(i)
- int i; /* Value to check for ones. */
- {
- register int value, shiftcount;
-
- value = (unsigned int) i;
- for (shiftcount = 0; value != 0; value >>= 4, shiftcount += 4) {
- if (value & 0xf) {
- return (lookup[value & 0xf] + shiftcount);
- }
- }
- return 0;
- }
- @
-
-
- 1.3.1.1
- log
- @Initial branch for Sprite server.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: /sprite/src/lib/c/bstring/RCS/ffs.c,v 1.3 89/06/19 14:15:25 jhh Exp $ SPRITE (Berkeley)";
- @
-
-
- 1.2
- log
- @Import WORD_ALIGN_MASK from machparam.h.
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: ffs.c,v 1.1 88/04/25 21:39:16 ouster Exp $ SPRITE (Berkeley)";
- d33 23
- d63 1
- a63 1
- * If there are no one-bits in the argument, then -1 is returned.
- d75 1
- a75 1
- register int i; /* Value to check for ones. */
- d77 1
- a77 1
- register int bitMask, result;
- d79 4
- a82 3
- for (bitMask = 1, result = 1; bitMask != 0; bitMask <<= 1, result++) {
- if (i & bitMask) {
- return result;
- d85 1
- a85 1
- return -1;
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d17 1
- a17 1
- static char rcsid[] = "$Header: ffs.c,v 1.1 88/04/25 13:25:41 ouster Exp $ SPRITE (Berkeley)";
- d24 2
- a25 2
- * address, then word-based operations may be used. Eventually this
- * mask needs to be handled in a more machine-independent fashion.
- d28 4
- a31 1
- #define WORDMASK 0x1
- @
-